# -*-coding:utf-8-*-

"""
指南针0号指标
0B指标
0A指标
"""
import pandas as pd
from _cfg import base as cfg
from hander.HanderFunc import HanderFunc
from hander.HanderBaoData import HanderBaoData
from hander.HanderZnzIndex import HanderZnzIndex
from dingding import dingding


def main_index_0(start_date='', end_date=''):
    dingding(title='处理指标信息', news=["处理指标信息-开始",
                                   "开始处理0号指标，0A指标，0B指标"])  # 发送钉钉消息
    date_list = HanderFunc.get_all_date(
        start_date=start_date, end_date=end_date)
    # print(date_list)
    # 执行数据获取
    hbd_obj = HanderBaoData()
    # 设置数据库连接
    hbd_obj.set_db_con(cfg=cfg)

    for i in date_list:
        # if date_list.index(i) == 1:
        data = hbd_obj.get_data_by_date(table_name='kd_data', date_=i)
        if not data.empty:
            hzi_obj = HanderZnzIndex()
            hzi_obj.set_pd_data(data)
            # 返回指标数据
            # 0号指标和0B指标
            index_0 = hzi_obj.index_0()
            pd_data3 = pd.DataFrame(index_0, index=[0])
            # 导入数据库
            hbd_obj.res_to_db(pd_data3, table_name='index_0')
            # 0A指标
            index_0A_data = hzi_obj.index_0A()
            pd_data4 = pd.DataFrame(index_0A_data, index=[0])
            # 导入数据库
            hbd_obj.res_to_db(pd_data4, table_name='index_0a')


if __name__ == '__main__':
    start_date = '2020-04-01'
    end_date = '2021-06-28'
    main_index_0(start_date=start_date, end_date=end_date)
